<template>
  <div class="app-container">
    <div class="search-box">
      <div class="search-hd">定时规则记录</div>
      <el-form
        ref="form"
        :model="searchField"
        label-width="100px"
        :inline="true"
      >
        <el-form-item label="规则名称" size="small">
          <el-input
            placeholder="请输入内容"
            v-model="searchField.ruleName"
            clearable
          >
          </el-input>
        </el-form-item>
        <el-form-item label="规则编号" size="small">
          <el-input
            placeholder="请输入内容"
            v-model="searchField.ruleNum"
            clearable
          >
          </el-input>
        </el-form-item>
        <el-form-item label="所属应用id" size="small">
          <el-input
            placeholder="请输入内容"
            v-model="searchField.wfAppid"
            clearable
          >
          </el-input>
        </el-form-item>
        <el-button
          type="success"
          size="small"
          @click="selectSelectived(searchField)"
          >查询</el-button
        >
      </el-form>
      <div class="search-bd">
        <!-- 新增监控源的dialog对话框 Form -->
        <!-- <el-button type="success" @click="dialogFormVisible = true" size="mini">新增</el-button>-->
        <el-dialog title="新增监控源" :visible.sync="dialogFormVisible">
          <el-form :model="form">
            <el-form-item label="监控项目" :label-width="formLabelWidth">
              <el-input
                v-model="form.mProject.name"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item label="监控源" :label-width="formLabelWidth">
              <el-input v-model="form.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="源类型" :label-width="formLabelWidth">
              <el-input v-model="form.type" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="告警配置" :label-width="formLabelWidth">
              <el-input v-model="form.configs" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="提醒人" :label-width="formLabelWidth">
              <el-input
                v-model="form.contact"
                autocomplete="off"
                placeholder="请输入正确的邮箱地址"
              ></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="addObject(form)">确 定</el-button>
          </div>
        </el-dialog>
        <!-- 修改监控源的dialog对话框 Form -->
        <el-dialog title="修改监控源" :visible.sync="dialogUpdateFormVisible">
          <el-form :model="form">
            <el-form-item label="监控项目" :label-width="formLabelWidth">
              <el-input
                v-model="form.mProject.name"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item label="监控源" :label-width="formLabelWidth">
              <el-input v-model="form.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="源类型" :label-width="formLabelWidth">
              <el-input v-model="form.type" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="告警配置" :label-width="formLabelWidth">
              <el-input v-model="form.configs" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="提醒人" :label-width="formLabelWidth">
              <el-input v-model="form.contact" autocomplete="off"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogUpdateFormVisible = false"
              >取 消</el-button
            >
            <el-button type="primary" @click="updateObject(form)"
              >确 定</el-button
            >
          </div>
        </el-dialog>
      </div>
    </div>
    <div class="main-box">
      <div class="main-hd">定时规则记录</div>
      <el-table
        v-loading="loading"
        :data="list"
        stripe
        max-height="500"
        fit
        highlight-current-row
      >
        <el-table-column label="序号" width="95" align="center">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column
          label="规则名称"
          prop="ruleName"
          align="center"
        ></el-table-column>
        <el-table-column
          label="规则编号"
          prop="ruleNum"
          align="center"
        ></el-table-column>
        <el-table-column
          label="所属应用id"
          prop="wfAppid"
          align="center"
        ></el-table-column>
        <!--<el-table-column label="告警配置" align="center">
          <template slot-scope="scope">
            <el-link type="primary" :underline="false" @click="set(scope.row.id)">配置</el-link>
          </template>
        </el-table-column>-->
        <el-table-column
          label="今日运行次数"
          prop="todayRuns"
          align="center"
        ></el-table-column>
        <el-table-column
          label="成功次数"
          prop="successRuns"
          align="center"
        ></el-table-column>
        <el-table-column
          label="失败次数"
          prop="failRuns"
          align="center"
        ></el-table-column>
        <el-table-column
          label="今日成功次数"
          prop="todaySuccessRuns"
          align="center"
        ></el-table-column>
        <el-table-column label="今日失败次数" align="center">
          <template slot-scope="scope">
            <el-link type="primary" :underline="false" @click="set(scope.row)">{{
              scope.row.todayFailRuns
            }}</el-link>
          </template>
        </el-table-column>
        <!-- <el-table-column label="今日失败次数" prop="todayFailRuns" align="center"></el-table-column> -->
        <el-table-column
          label="最近一次运行时间"
          prop="lastRuntime"
          align="center"
        ></el-table-column>
      </el-table>
      <div class="page-box">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="searchField.page"
          :page-sizes="[10, 15, 20, 25, 30, 50]"
          :page-size="searchField.limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
      <!-- 失败事件 -->
        <el-dialog
          title="异常信息"
          :visible.sync="dialogVisiblebpm"
          width="50%"
        >
          <el-table
            :data="arr"
            height="450"
            border
            style="width: 100%"
          >
            <el-table-column prop="name" label="字段"> </el-table-column>
            <el-table-column prop="val" label="值"> </el-table-column>
          </el-table>
          <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisiblebpm = false">取 消</el-button>
            <el-button type="primary" @click="dialogVisiblebpm = false"
              >确 定</el-button
            >
          </span>
        </el-dialog>
    </div>
  </div>
</template>

<script>
import { findAllTimingRuleRecord, monitorfindeone } from "@/api/table";

export default {
  data() {
    return {
      list: null,
      loading: true,
      total: 10,
      searchField: {
        ruleName: "",
        ruleNum: "",
        wfAppid: "",
        page: 1,
        limit: 15,
      },
      checkedId: "",
      checkList: [],
      dialogVisiblebpm: false,
      dialogFormVisible: false,
      dialogUpdateFormVisible: false,
      form: {
        id: "",
        pid: "",
        name: "",
        type: "",
        configs: "",
        contact: "",
        isDelete: 0,
        address: "",
        extention: "",
        serialVersionUID: 0,
        mProject: {
          id: "",
          name: "",
          server: "",
          db: "",
          mission: "",
          service: "",
          number: "",
          provider: "",
          tel: "",
          extention: "",
        },
      },
      formLabelWidth: "120px",
      arr:[]
    };
  },
  created() {
    this.initListData();
  },
  methods: {
    //搜索
    selectSelectived(searchField) {
      console.log(searchField);
      findAllTimingRuleRecord(this.searchField).then((res) => {
        this.$message.success("查询成功");
        this.list = res.data.rows;
        this.total = res.data.total;
        this.loading = false;
      });
    },
    // 配置
    set(row) {
      console.log(row);
      this.dialogVisiblebpm = true;
      this.monitorfindeone(row.ruleNum)
    },
    monitorfindeone(ruleNum) {
      monitorfindeone({wfNum:ruleNum}).then((res) => {
        console.log(res);
        let bpmdata=res.data

        console.log(bpmdata);
        let ary
         for (let key in bpmdata) {
          ary = {};
          if (key != "delete") {
            ary.name = key;
            ary.val = bpmdata[key];
            this.arr.push(ary);
          }
        }
        // this.arr=res.data
      });
    },
    initListData() {
      this.loading = true;
      findAllTimingRuleRecord(this.searchField).then((res) => {
        this.list = res.data.rows;
        this.total = res.data.total;
        this.loading = false;
      });
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.searchField.limit = val;
      this.pagingQuery();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      console.log(`当前页: ` + val);
      this.searchField.page = val;
      this.pagingQuery();
    },
    // 初始化dialog弹框的内容
    initDialogContent() {
      this.form = {
        id: "",
        pid: "",
        name: "",
        type: "",
        configs: "",
        contact: "",
        isDelete: 0,
        address: "",
        extention: "",
        serialVersionUID: 0,
        mProject: {
          id: "",
          name: "",
          server: "",
          db: "",
          mission: "",
          service: "",
          number: "",
          provider: "",
          tel: "",
          extention: "",
        },
      };
    },
   
    // 删除确认的提示框
    open(id) {
      this.$confirm("此操作将永久删除该监控源, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.del(id);
      });
    },
   
    // 分页查询函数
    pagingQuery: function () {
      findAllTimingRuleRecord(this.searchField).then((res) => {
        this.list = res.data.rows;
        this.total = res.data.total;
        this.loading = false;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.redColor {
  color: red;
}
.search-box {
  margin-bottom: 15px;
  .search-hd {
    border-left: 2px solid #00a73c;
    padding: 10px;
    margin-bottom: 10px;
  }
  .search-bd {
    .el-button--small {
      margin-top: 3px;
    }
  }
}
.main-box {
  .main-hd {
    height: 40px;
    line-height: 40px;
    background: #00a73c;
    color: #fff;
    padding-left: 10px;
  }
  .page-box {
    padding: 10px;
    text-align: center;
  }
}
</style>
